package tests;

import common.Utils;
import org.openqa.selenium.Alert;
import org.openqa.selenium.By;

import java.io.IOException;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User:DELL
 * Date:2025-03-29
 * Time:21:24
 */
public class MessageDetailsPage extends Utils {
    public static String url="http://127.0.0.1:8080/client.html";
    public MessageDetailsPage() {
        super(url);
    }
    //zhangsan给lisi发送消息
    public void ChatSuc() throws InterruptedException, IOException {
        //点击消息列表标签页
        driver.findElement(By.cssSelector("body > div.client-container > div > div.left > div.tab > div.tab-session")).click();
        //点击具体会话
        driver.findElement(By.cssSelector("#session-list > li:nth-child(1)>h3")).click();
        Thread.sleep(3000);
        //在输入框发送消息
        driver.findElement(By.cssSelector("body > div.client-container > div > div.right > textarea")).sendKeys("你好呀！");
        Thread.sleep(3000);
        //点击发送按钮
        driver.findElement(By.cssSelector("body > div.client-container > div > div.right > div.ctrl > button")).click();
        Thread.sleep(3000);
        //通过屏幕截图验证消息是否发送成功
        getScreenShot(getClass().getName());

    }
    //lisi收到消息
    public void Receive() throws InterruptedException {
        //退出登录
        //1.返回到登录页面
        driver.navigate().back();
        //2.清空用户账号和密码
        driver.navigate().refresh();
        //登录李四用户名和密码
        Thread.sleep(3000);
        driver.findElement(By.cssSelector("#username")).sendKeys("lisi");
        driver.findElement(By.cssSelector("#password")).sendKeys("123");
        driver.findElement(By.cssSelector("#submit")).click();
        Thread.sleep(3000);
        //出现登录成功弹窗，点击确定进入列表页
        Alert alert=driver.switchTo().alert();
        alert.accept();
        Thread.sleep(3000);
        //检查点击确定之后是否登陆成功，进入会话列表页
        driver.findElement(By.cssSelector("body > div.client-container > div > div.left > div.user"));
        Thread.sleep(3000);
        //点击zhangsan会话页
        driver.findElement(By.cssSelector("#session-list > li:nth-child(1) > h3")).click();
        //获取好友名
        String name=driver.findElement(By.cssSelector("body > div.client-container > div > div.right > div.message-show > div.message.message-left > div > h4")).getText();
        //获取最后一条消息
        String text=driver.findElement(By.cssSelector(" body > div.client-container > div > div.right > div.message-show > div.message.message-left > div > p")).getText();
        //判断好友是否一致
        assert name.equals("zhangsan");
        //判断内容
        assert text.equals("你好呀！");
        driver.quit();

    }
}
